package com.atguigu.gmall.cart.service.impl;


import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.cart.service.CartInfoAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class CartInfoAsyncServiceImpl implements CartInfoAsyncService {

    @Autowired
    CartInfoMapper cartInfoMapper;

    @Async
    @Override
    public void updateById(CartInfo cartInfo) {
        cartInfoMapper.update(cartInfo,new QueryWrapper<CartInfo>()
                            .eq("user_id",cartInfo.getUserId())
                            .eq("sku_id",cartInfo.getSkuId()));
    }

    @Async
    @Override
    public void insert(CartInfo cartInfo) {
        cartInfoMapper.insert(cartInfo);
    }

    @Override
    public void updateByIdExt(String userTempId, String userId) {
        CartInfo cartInfo = new CartInfo();
        cartInfo.setUserId(userId);
        cartInfoMapper.update(cartInfo,new QueryWrapper<CartInfo>().eq("user_id",userTempId));
    }

    @Override
    public void deleteById(String userTempId) {
        cartInfoMapper.delete(new QueryWrapper<CartInfo>().eq("user_id",userTempId));
    }


}
